package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    TeacherDao teacherDao = new TeacherDao();

    public boolean addTeacher(Teacher te) {
        return teacherDao.addTeacher(te);
    }

    //判断id是否存在
    public boolean exit(String id) {
        Teacher[] t = teacherDao.getTe();
        for (int i = 0; i < t.length; i++) {
            Teacher teacher = t[i];
            if (teacher != null && teacher.getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

    //打印所有老师信息
    public void searchTeacher() {
        Teacher[] te = teacherDao.getTe();
        for (int i = 0; i < te.length; i++) {
            if (te[i] != null) {
                System.out.println(te[i].getId() + "\t" + te[i].getName() + "\t" + te[i].getAge() + "\t" + te[i].getBirthday());
            }
        }
    }

    //数组是否为空
    public Teacher[] useTeacher() {
        Teacher[] te = teacherDao.getTe();
        for (int i = 0; i < te.length; i++) {
            if (te[i] != null) {
                return te;
            }
        }
        return null;
    }

    //删除传递
    public void deleteTeacher(String id) {
        teacherDao.deleteTeacher(id);
    }

    //修改 传递
    public void changeTeacher(Teacher te) {
        teacherDao.changeTeacher(te);
    }
}
